#include <iostream>
#include <string>
#include "stack.h"
using namespace std;

const string oper = { '+', '-', '*', '/', '(', ')', '#' };

int getPriority(char c)
{
	if (c == '(')
		return 1;
	else if (c == '+' || c == '-')
		return 2;
	else if (c == '*' || c == '/')
		return 3;
	else if (c == ')')
		return 4;
	else
	return -1;
}

bool if_oper(char ch) {
	for (int i = 0; i < 7; i++) {
		if (ch == oper[i]) {
			return true;
		}
	}
	return false;
}

string conver(Stack op, string &exp, int length)
{
    string postexp;
    op.push('=');
    for (int i = 0; i < length; i++)
    {
        char ch = exp[i];
        if (!if_oper(ch))
        {
            int num = i+1;
            char ch1 = exp[num];
            int sum = 0;
            while (!if_oper(ch1) && num < length)
            {
                sum++;
                ch1 = exp[++num];
            }
            if (sum > 0)
            {
                string tmp1(exp, i+1, sum);
                postexp += (ch + tmp1 + '#');
                i = num - 1;
            }
            else
            {
                postexp += ch;
            }
            continue;
        }
        else if (ch == '(')
        {
            op.push(ch);
            continue;
//            switch (Precede(op.top(), ch))
//            {
//                case '<' : op.push(ch); break;
//                case '=' : while(op.top() != '(')
//                           {
//                                char c1 = op.pop();
//                                postexp += c1;
//                           };
//                           op.pop(); break;
//                case '>' : char c;
//                            do
//                            {
//                                char c = op.pop();
//                                postexp += c;
//                            }while(Precede(op.top(), c) == '>');
//                            break;
//            }
        }
        else if (ch == ')')
        {
            while (op.top() != '(')
            {
                char c1 = op.pop();
                postexp += c1;
            }
            op.pop();
            continue;
        }
        else
        {
            if (op.empty())
            {
                op.push(ch);
                continue;
            }
            else
            {
                while (!op.empty())
                {
                    char c = op.top();
                    if (getPriority(ch) <= getPriority(c))
                    {
                        postexp += c;
                        op.pop();
                    }
                    else
                        break;
                }
                op.push(ch);
                continue;
            }
        }
    }
    char res = op.pop();
    while (res != '=')
    {
        postexp += res;
        res = op.pop();
    }
    return postexp;
}

void cal(string &postexp, int length)
{
    Stack st;
    char ch;
    for (int i = 0; i < length; i++)
    {
        string tmp;
        ch = postexp[i];
        if (ch == '#')
            continue;
        if (!if_oper(ch))
        {
            tmp += ch;
            int num = i+1;
            char ch1 = postexp[num];
            bool flag = 0;
            for (int j = num; j < length; j++)
            {
                if (postexp[j] == '#')
                {
                    flag = true;
                    break;
                }
                else if (if_oper(postexp[j]))
                {
                    break;
                }
            }
            int sum = 0;
            while (ch1 != '#' && flag)
            {
                sum++;
                tmp += ch1;
                ch1 = postexp[++num];
            }
            if (sum > 0)
            {
                i = num - 1;
            }
            int n = atoi(tmp.c_str());
            st.push(n);
            continue;
        }
        else
        {
            int l2 = st.pop(), l1 = st.pop();
//            cout << l2 << ch << l1 << "=" << endl;
            int res = 0;
            switch (ch)
            {
                case '+' : res = l1 + l2; st.push(res); break;
                case '-' : res = l1 - l2; st.push(res); break;
                case '*' : res = l1 * l2; st.push(res); break;
                case '/' : if (l2 == 0)
                           {
                               cout << "除数不能为0" << endl;
                               break;
                           }
                           res = l1 / l2; st.push(res); break;
            }
        }
    }
    int res = st.top();
    cout << res << endl;
}

int main()
{
    Stack op;
    string exp, postexp;
    cin >> exp;
    int length = exp.length();
    postexp = conver(op, exp, length);
    cout << postexp << endl;
    int length1 = postexp.length();
    cal(postexp, length1);
    return 0;
}
